window.onload= function () {
	
	item = document.getElementsByClassName('item');

	click_item = document.getElementsByClassName('click_item');

	left_click = document.getElementById('left_click');

	right_click = document.getElementById('right_click');

	banner = document.getElementById('banner');

	num = 0;
	function run() {
		
		for (var i = 0; i < item.length; i++) {
			item[i].style.display="none";
			click_item[i].style.background="rgba(0,0,0,0.3)";
		}

		item[num].style.display="block";
		click_item[num].style.background="rgba(255,255,255,0.6)";

		if(num==item.length-1){
			num = 0;
		}else{
			num++;
		}
	}

	time = setInterval(run,1000);

	banner.onmouseover= function () {
		clearInterval(time);
	}

	banner.onmouseout= function () {
		time = setInterval(run,1000);
	}

	right_click.onclick= function () {
		run();
	}

	left_click.onclick= function () {
		console.log(num);
		if(num==1){
			num = item.length-1;
		}else if(num==0){
			num = item.length-2;
		}else{
			num -=2;
		}
		run();
	}

	for (var i = 0; i < click_item.length; i++) {
		click_item[i].index = i;
		click_item[i].onclick = function () {
			num = this.index;
			run();
		}
	}

}
